package com.iron.consumer.controller;

import com.iron.common.core.util.R;
import com.iron.consumer.entity.ConfigInfo;
import com.iron.consumer.entity.TxA;
import com.iron.consumer.entity.TxB;
import com.iron.consumer.feign.IronProviderFeign;
import com.iron.consumer.service.ConfigInfoService;
import com.iron.consumer.service.TxAService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * consumer controller
 *
 * @author YT
 * @date 2019-06-11
 */
@RestController
@AllArgsConstructor
@Slf4j
public class ConsumerController {

    private final IronProviderFeign ironProviderFeign;

    private final TxAService txAService;

    private final ConfigInfoService configInfoService;

    @GetMapping("/consumer/get")
    public R getProviderMsg() {
        return ironProviderFeign.providerTest();
    }

    @GetMapping("/comsumer/port")
    public R getPort(){
        log.info("访问 1");
        return R.ok("访问 1");
    }

    @GetMapping("/consumer/save")
    public R saveTxATxB() {
        TxA txA = new TxA();
        txA.setName("iron-consumer");

        TxB txB = new TxB();
        txB.setName("iron-sfm");

        return R.ok(txAService.testSaveTxATxB(txA, txB));
    }

    @GetMapping("/test1")
    public R test1() {
        List<ConfigInfo> configInfos = configInfoService.list();
        return R.ok(configInfos);
    }
}
